package com.lzk.pet.rocketmq;

import com.lzk.order.domain.OrderPetAcquisition;
import com.lzk.order.mapper.OrderPetAcquisitionMapper;
import io.netty.util.CharsetUtil;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@RocketMQMessageListener(topic = "queue_test_topic",selectorExpression = "*",consumerGroup = "order_consumer_group")
public class RocketMQMsgListener implements RocketMQListener<MessageExt> {
    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;
    @Override
    public void onMessage(MessageExt message) {

            byte[] body = message.getBody();
            //接收到订单编号
            String orderSn = new String(body, CharsetUtil.UTF_8);
            //通过订单编号去查询这个订单
            OrderPetAcquisition order = orderPetAcquisitionMapper.loadByOrderSn(orderSn);
            if(order.getState() == 0){//订单超过两天未处理
                //修改订单状态为取消-1
                orderPetAcquisitionMapper.updateStaAndShopId(orderSn);
                System.out.println("取消订单完成"+new Date().toLocaleString());
            }



    }
}